/**
 * @description router全局配置，如有必要可分文件抽离
 */

import Vue from "vue";
import VueRouter from "vue-router";
import Layout from "@/layouts";
import EmptyLayout from "@/layouts/EmptyLayout";
import { routerMode } from "@/config/settings";

Vue.use(VueRouter);

export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
  },
  {
    path: "/register",
    component: () => import("@/views/register/index"),
    hidden: true,
  },
  {
    path: "/401",
    name: "401",
    component: () => import("@/views/401"),
    hidden: true,
  },
  {
    path: "/404",
    name: "404",
    component: () => import("@/views/404"),
    hidden: true,
  },
];

/*当settings.js里authentication配置的是intelligence时，views引入交给前端配置*/
export const asyncRoutes = [
  // {
  //   path: "/",
  //   component: Layout,
  //   redirect: "/index",
  //   children: [
  //     {
  //       path: "/index",
  //       name: "Index",
  //       component: () => import("@/views/index/index"),
  //       meta: {
  //         title: "首页",
  //         icon: "home",
  //         affix: true,
  //         noKeepAlive: true,
  //       },
  //     },
  //   ],
  // },

  {
    "id": 8,
    "pid": 0,
    "weight": 0,
    "status": true,
    "menu": true,
    "condition": "",
    "front": "查询,添加,修改,删除,状态,批量删除,导出数据,导入数据",
    "meta": {
      "title": "首页",
      "icon": "th-large",
      "affix": 0,
      "badge": "",
      "breadcrumb": false,
      "remixIcon": "th-large",
      "noKeepAlive": 0
    },
    "component": Layout,
    "path": "/",
    "level": 0,
    "children": [
      {
        "id": 9,
        "pid": 8,
        "weight": 1,
        "status": true,
        "menu": true,
        "condition": "",
        "front": "查询,添加,修改,删除,状态,批量删除,导出数据,导入数据",
        "meta": {
          "title": "首页",
          "icon": "th-large",
          "affix": 0,
          "badge": "",
          "breadcrumb": false,
          "remixIcon": "th-large",
          "noKeepAlive": 0
        },
        "component":  () => import("@/views/index/index") ,
        "path": "/index",
        "level": 1
      }
    ]
  },

  // {
  //   path: "/system",
  //   component: Layout,
  //   redirect: "system/admin",
  //   meta: {
  //     title: "权限管理",
  //     icon: "th-large",
  //     affix: false,
  //     noKeepAlive: false,
  //   },
  //   children: [
  //     {
  //       path: "/system/admin",
  //       name: "/system/admin",
  //       component: () => import("@/views/system/auth/admin/index"),
  //       meta: {
  //         title: "用户管理",
  //         icon: "th-large",
  //         affix: false,
  //         noKeepAlive: false,
  //       },
  //     },
  //     {
  //       path: "/system/menu",
  //       name: "/system/admin",
  //       component: () => import("@/views/system/auth/menu/index"),
  //       meta: {
  //         title: "菜单管理",
  //         icon: "th-large",
  //         affix: false,
  //         noKeepAlive: false,
  //       },
  //     },
  //     {
  //       path: "/system/role",
  //       name: "/system/admin",
  //       component: () => import("@/views/system/auth/role/index"),
  //       meta: {
  //         title: "角色组",
  //         icon: "th-large",
  //         affix: false,
  //         noKeepAlive: false,
  //       },
  //     },
  //   ],
  // },


  {
    "id": 1,
    "pid": 0,
    "weight": 1,
    "status": true,
    "menu": false,
    "condition": "",
    "front": "查询,添加,修改,删除,状态,批量删除,导出数据,导入数据",
    "meta": {
      "title": "权限管理",
      "icon": "th-large",
      "affix": 0,
      "badge": "",
      "breadcrumb": false,
      "remixIcon": "th-large",
      "noKeepAlive": 0
    },
    "component": Layout,
    "path": "/system",
    "level": 0,
    "children": [
      {
        "id": 4,
        "pid": 1,
        "name": "SystemAdmin",
        "weight": 1,
        "status": true,
        "menu": false,
        "condition": "",
        "front": "查询,添加,修改,删除,状态,批量删除,导出数据,导入数据",
        "meta": {
          "title": "用户管理",
          "icon": "th-large",
          "affix": 0,
          "badge": "",
          "breadcrumb": false,
          "remixIcon": "th-large",
          "noKeepAlive": 0
        },
        component:  () => import("@/views/system/auth/admin/index"),
        "path": "/system/admin",
        "level": 1
      },
      {
        "id": 5,
        "pid": 1,
        "weight": 1,
        "status": true,
        "menu": false,
        "condition": "",
        "front": "查询,添加,修改,删除,状态,批量删除,导出数据,导入数据",
        "meta": {
          "title": "菜单管理",
          "icon": "th-large",
          "affix": 0,
          "badge": "",
          "breadcrumb": false,
          "remixIcon": "th-large",
          "noKeepAlive": 0
        },
        "component": () => import("@/views/system/auth/menu/index"),
        "path": "/system/menu",
        "level": 1
      },
      {
        "id": 6,
        "pid": 1,
        "weight": 1,
        "status": true,
        "menu": false,
        "condition": "",
        "front": "查询,添加,修改,删除,状态,批量删除,导出数据,导入数据",
        "meta": {
          "title": "角色组",
          "icon": "th-large",
          "affix": 0,
          "badge": "",
          "breadcrumb": false,
          "remixIcon": "th-large",
          "noKeepAlive": 0
        },
        "component": () => import("@/views/system/auth/role/index"),
        "path": "/system/role",
        "level": 1
      }
    ]
  },



  {
    path: "/personalCenter",
    component: Layout,
    hidden: true,
    redirect: "personalCenter",
    children: [
      {
        path: "personalCenter",
        name: "PersonalCenter",
        component: () => import("@/views/personalCenter/index"),
        meta: {
          title: "个人中心",
        },
      },
    ],
  },
  {
    path: "*",
    redirect: "/404",
    hidden: true,
  },
];

const router = new VueRouter({
  mode: routerMode,
  scrollBehavior: () => ({
    y: 0,
  }),
  routes: constantRoutes,
});
/* const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
}; */

export function resetRouter() {
  router.matcher = new VueRouter({
    mode: routerMode,
    scrollBehavior: () => ({
      y: 0,
    }),
    routes: constantRoutes,
  }).matcher;
}

export default router;
